package com.gismore.jsonp.core;

import com.google.common.collect.Lists;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * Description: 通过Jsoup解析HTML
 * Author: zhaolei
 * Date: Since 2018-03-11 00:31:26
 */
public class Collector {

	public static List<String> collect(String url){
		List<String> retList = Lists.newArrayList();
		try {
			Document doc = Jsoup.connect(url).get();
			retList = doc.select("a[href]")
				.stream()
				.filter(element -> element.attr("href").startsWith("ftp://"))
				.map(element -> element.attr("href"))
				.collect(toList());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return retList;
	}
}
